/*******************************************************************************  
* 文件名称：蓝桥杯单片机模板
* 实验目的：完成赛题要求
* 程序说明：
* 字体格式：UTF-8
* 日期版本：2023-3-21	V1.0
*******************************************************************************/

/*********头文件*********/
#include <STC15F2K60S2.H>
#include "intrins.h"
#include "onewire.h"
#include "ds1302.h"
#include "iic.h"
#include "SMG.h"
#include "Timer.h"
#include "Key.h"


/*********宏定义*********/
#define uchar unsigned char 
#define uint unsigned int

/*******数码管变量*******/




void main()
{
	Power_All_Init();
	
	Timer0_Init();
	Timer2_Init();
	
	DS1302_Init();
	DS1302_SetTime();
	
	while(1)
	{
		DS1302_ReadTime();
		SMG_Show_Data();
		Key4_Proc();		
	}
	
}


//定时器0中断服务函数
void Timer0_Rountine(void) interrupt 1
{
	static unsigned int  T0Count0;
	static unsigned char key4_count;	//独立按键

	T0Count0++;
	if(T0Count0 >= 1000)
	{
		//执行操作
		_aaa += 2;
		T0Count0 = 0;	//软件复位
	}
	
	if (++key4_count >= 10)
	{
		key4_count = 0;
		uc_Key_flag = 0;
	}
}	


// 定时器2 中断服务函数模板
void Timer2_Routine() interrupt 12  // 1T 16位自动重载
{
    static unsigned int  T2Count0;
	static unsigned char i, smg_scan_cnt;
		
	T2Count0++;	
	if(T2Count0 >= 1000)
	{
		//执行操作
		SMG_number++;
		T2Count0 = 0;
	}
	
	smg_scan_cnt++;				//数码管扫描时间
	if (smg_scan_cnt >= 1)		//2ms扫描一次数码管
	{
		smg_scan_cnt = 0;		//软件复位
		P2 = 0xE0; P0 = 0xFF;	//定时器扫描数码管，先消影，就不会出现残影了!!！
		
		P2 = 0xC0; P0 = 0x01<<i;
		
		if (menu_index == 1) {P2 = 0xE0; P0 = menu1[i]; P2 = 0;}
		if (menu_index == 2) {P2 = 0xE0; P0 = menu2[i]; P2 = 0;}
		if (menu_index == 3) {P2 = 0xE0; P0 = menu3[i]; P2 = 0;}
		if (menu_index == 4) {P2 = 0xE0; P0 = menu4[i]; P2 = 0;}
		if (menu_index == 5) {P2 = 0xE0; P0 = menu5[i]; P2 = 0;}
		if (menu_index == 6) {P2 = 0xE0; P0 = menu6[i]; P2 = 0;}
		i ++;
		i = i % 8;
		
	}
	
}
